package org.jypj.dev.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.jypj.dev.model.OeoProblem;
import org.jypj.dev.dao.OeoProblemDao;
import org.jypj.dev.service.OeoProblemService;
import org.jypj.dev.util.Page;
import org.jypj.dev.util.StringUtil;

@Service("oeoProblemService")
public class OeoProblemServiceImpl implements OeoProblemService {

    @Resource
    private OeoProblemDao oeoProblemDao;

    /**
    * 保存
    * 所有字段全都保存
    * @param oeoProblem
    * @return 保存后的对象包括ID
    */
    public int saveOeoProblem(OeoProblem oeoProblem){
        if(StringUtil.isEmpty(oeoProblem.getId())){
            String uuid =UUID.randomUUID().toString().replace("-", "").trim();
            oeoProblem.setId(uuid);
        }
        return oeoProblemDao.saveOeoProblem(oeoProblem);
    }

    /**
    * 根据ID删除
    * @param id 主键ID
    * @return 删除记录数
    */
    public int deleteOeoProblemById(String id){

        return oeoProblemDao.deleteOeoProblemById(id);
    }

    /**
    * 根据对象删除
    * @param oeoProblem
    * @return
    */
    public int deleteOeoProblemByObject(OeoProblem oeoProblem){

        return oeoProblemDao.deleteOeoProblemByObject(oeoProblem);
    }

    /**
    * 更新
    * 更新所有字段
    * @param oeoProblem
    * @return 保存后的对象包括ID
    */
    public int updateOeoProblem(OeoProblem oeoProblem){

        return oeoProblemDao.updateOeoProblem(oeoProblem);
    }

    /**
    * 按ID查询
    * @parm id 主键ID
    * @return OeoProblem
    */
    public OeoProblem selectOeoProblemById(String id){

        return oeoProblemDao.selectOeoProblemById(id);
    }

    /**
    * 分页查询 包含条件
    * @param page 分页对象
    * @param map  查询条件
    * @return  List<OeoProblem>
    */
    public Page selectOnePageByMap(Page page,Map<String,Object> map){
        List<OeoProblem> oeoProblems =oeoProblemDao.selectOnePageByMap(page,map);
        if(oeoProblems!=null&&oeoProblems.size()>0){
            page.setResult(oeoProblems);
        }else{
            page.setResult(new ArrayList<OeoProblem>());
        }
        return page;
    }
    /**
    * 分页查询 包含对象条件
    * @param page 分页对象
    * @param oeoProblem  查询条件
    * @return Page
    */
    public Page selectOnePageByOeoProblem(Page page,OeoProblem oeoProblem){
        List<OeoProblem> oeoProblems =oeoProblemDao.selectOnePageByOeoProblem(page,oeoProblem);
        if(oeoProblems!=null&&oeoProblems.size()>0){
            page.setResult(oeoProblems);
        }else{
            page.setResult(new ArrayList<OeoProblem>());
        }
        return page;
    }

    /**
    * 按条件查询全部的
    * @param map  查询条件
    * @return  List<OeoProblem>
    */
    public List<OeoProblem> selectAllByMap(Map<String,Object> map){
        return oeoProblemDao.selectAllByMap(map);
    }


    /**
    * 按条件查询全部的
    * @param oeoProblem  查询条件
    * @return  List<OeoProblem>
    */
    public List<OeoProblem> selectAllByOeoProblem(OeoProblem oeoProblem){

        return oeoProblemDao.selectAllByOeoProblem(oeoProblem);
    }

    /**
    * 按条件查询单个对象
    * @param map  查询条件
    * @return  OeoProblem
    */
    public OeoProblem selectObjectByMap(Map<String,Object> map){

        return oeoProblemDao.selectObjectByMap(map);
    }

    /**
    * 按条件查询单个对象
    * @param oeoProblem  查询条件
    * @return  OeoProblem
    */
    public OeoProblem selectObjectByOeoProblem(OeoProblem oeoProblem){

        return oeoProblemDao.selectObjectByOeoProblem(oeoProblem);
    }
}